import cv2
import matplotlib.pyplot as plt
import numpy as np
from numba import uint8

def cv_show(name,img):
    cv2.imshow(name,img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

img = cv2.imread('C:/Users/nic/Desktop/opencv/picture/lost.JPG')
# erosion
kernel = np.ones((3,3),np.uint8)
erosion = cv2.erode(img,kernel,iterations=1)
#delate
dilate = cv2.dilate(img,kernel,iterations=1)
#stack
res = np.hstack((erosion,dilate))
cv_show('all_image',res)
#open and close
opening = cv2.morphologyEx(img,cv2.MORPH_OPEN,kernel)
closing = cv2.morphologyEx(img,cv2.MORPH_CLOSE,kernel)
#stack
res = np.hstack((opening,closing))
cv_show('all_image',res)
#gradient
gradient = cv2.morphologyEx(img,cv2.MORPH_GRADIENT,kernel)
cv_show('all_image',gradient)
#tophat and blackhat
tophat = cv2.morphologyEx(img,cv2.MORPH_TOPHAT,kernel)
blackhat = cv2.morphologyEx(img,cv2.MORPH_BLACKHAT,kernel)
#stack
res = np.hstack((tophat,blackhat))
cv_show('all_image',res)



